var ds = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
						url : 'manuscriptWork_list.action',
						method : 'POST'
					}),
			reader : new Ext.data.JsonReader({
						root : 'manuscriptWorks',
						totalProperty : 'totalCount'
					}, [{
						name : 'manuscriptId',
						mapping : 'manuscriptId',
						type : 'long',
						hidden : 'true'
					},{
								name : 'manuscriptWorkId',
								mapping : 'manuscriptWorkId',
								type : 'long',
								hidden : 'true'
							}, {
								name : 'title',
								mapping : 'manuscript.title',
								type : 'string'
							},{
								name : 'description',
								mapping : 'description',
								type : 'string'
							}, {
								name : 'status',
								mapping : 'status',
								type : 'short'
							}, {
								name : 'type',
								mapping : 'type',
								type : 'string'
							}, {
								name : 'wordNum',
								mapping : 'wordNum',
								type : 'int'
							}, {
								name : 'assignerName',
								mapping : 'assignerName',
								type : 'string'
							}, {
								name : 'principalName',
								mapping : 'principalName',
								type : 'string'
							}, {
								name : 'workerNum',
								mapping : 'workerNum',
								type : 'short'
							}, {
								name : 'operation',
								type : 'string'
							}])
		});

var cm_menuscriptWork = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
	header : "稿件标题",
	width:200,
	dataIndex : 'title',
	sortable : true,
	renderer : function(value, metadata, record) {
	return "<a href = 'javascript:void(0)' onclick=javascript:showManuscript('"
		+ record.data.manuscriptId + "')> " + escapeHTML(value) + " </a>"; 
	}
},{
	header : "任务描述",
	width:200,
	dataIndex : 'description',
	sortable : true,
	renderer : function(value, metadata, record) {
		var sa = '';
		if(value == '')
		{
			sa = '无任务描述';
		}else{
			sa = value;
		}
			
		return "<a href = 'javascript:void(0)' onclick=javascript:showManuscriptWork('"
	         	+ record.data.manuscriptId  + "','"
				+ record.data.manuscriptWorkId + "')> " + escapeHTML(sa) + " </a>";
	}
}, {
	header : "工作类型",
	width:90,
	dataIndex : 'type',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (value == 1) {
			return '翻译';
		} else if (value == 2) {
			return '校审';
		} else if (value == 3) {
			return '校对';
		} else {
			return '审核';
		};
	}
}, {
	header : "工作状态",
	width:100,
	dataIndex : 'status',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (value == 1) {
			return '分发完成';
		} else if (value == 2) {
			return '工作进行中';
		} else if (value == 3) {
			return '工作完成';
		}else if (value == 4) {
			return '工作部分完成';
		} else if (value == 10) {
			return '工作被拒绝';
		} else if (value == 11) {
			return '工作被取消';
		};
	}
}, {
	header : "字数",
	width:80,
	dataIndex : 'wordNum',
	sortable : true
}, {
	header : "分发人",
	dataIndex : 'assignerName',
	sortable : true
}, {
	header : "统稿人",
	dataIndex : 'principalName',
	sortable : true
}, {
	header : "工作人数",
	width:80,
	dataIndex : 'workerNum',
	sortable : true
}, {
	header : "操作",
	width:130,
	dataIndex : 'operation',
	sortable : true,
	renderer : function(value, metadata, record) {
		if (record.data.status == 1) {
			return "<a href = 'javascript:void(0)' onclick=javascript:addScriptWorker('"
					+ record.data.manuscriptId
					+ "','" + record.data.manuscriptWorkId + "')>增加 </a>&nbsp;<a href='javascript:void(0)' onclick=javascript:deleteScriptWorker('"
					+ record.data.manuscriptId
					+"','" + record.data.manuscriptWorkId + "')>减少</a>&nbsp;<a href = 'javascript:void(0)' onclick=javascript:cancelManuscriptWork('"
					+ record.data.manuscriptWorkId + "')>取消 </a>";
		} else if (record.data.status == 2) {
			return "<a href = 'javascript:void(0)' onclick=javascript:addScriptWorker('"
					+ record.data.manuscriptId
					+ "','" + record.data.manuscriptWorkId + "')>增加 </a>&nbsp;<a href='javascript:void(0)' onclick=javascript:deleteScriptWorker('"
					+ record.data.manuscriptId
					+"','" + record.data.manuscriptWorkId+ "')>减少</a>&nbsp;<font color='#cccccc'>取消</font>";
		} else{
			
			return "<font color='#cccccc'>增加</font>&nbsp;&nbsp;<font color='#cccccc'>减少</font>&nbsp;<font color='#cccccc'>取消</font>";
		}
	}
}]);

var select_manuscriptWork = new Ext.Button({
			text : '查找稿件工作',
			width : 100,
			iconCls:"manuscript_search",
			handler : function() {

				manuscriptWorkForm = new Ext.form.FormPanel({
							labelAlign : 'right',
							labelWidth : 80,
							frame : true,
							width : 600,
							id : 'bb',
							store : ds,
							items : [{
										xtype : 'panel',
										layout : "column",
										isFormField : true,
										fieldLabel : '稿件类型',
										itemCls : 'clear',
										items : [{
													xtype : "radio",
													boxLabel : "翻译",
													name : "manuscriptWorkType",
													inputValue : "1"
												}, {
													xtype : "radio",
													boxLabel : "校审",
													name : "manuscriptWorkType",
													inputValue : "2"

												}, {
													xtype : "radio",
													boxLabel : "校对",
													name : "manuscriptWorkType",
													inputValue : "3"
												}, {
													xtype : "radio",
													boxLabel : "审核",
													name : "manuscriptWorkType",
													inputValue : "4"
												}]
									}, {
										xtype : 'panel',
										layout : "column",
										isFormField : true,
										fieldLabel : '工作状态',
										itemCls : 'clear',
										items : [{
													xtype : "radio",
													boxLabel : "分发完成",
													name : "manuscriptWorkStatus",
													inputValue : "1"
												}, {
													xtype : "radio",
													boxLabel : "工作进行中",
													name : "manuscriptWorkStatus",
													inputValue : "2"

												}, {
													xtype : "radio",
													boxLabel : "工作完成",
													name : "manuscriptWorkStatus",
													inputValue : "3"
												},{
													xtype : "radio",
													boxLabel : "工作部分完成",
													name : "manuscriptWorkStatus",
													inputValue : "4"
												}, {
													xtype : "radio",
													boxLabel : "工作被拒绝",
													name : "manuscriptWorkStatus",
													inputValue : "10"
												}, {
													xtype : "radio",
													boxLabel : "工作被取消",
													name : "manuscriptWorkStatus",
													inputValue : "11"
												}]
									}, {
										xtype : 'datefield',
										name : 'startTime',
										editable : false,
										id : 'startTime',
										fieldLabel : '开始日期',
										format : 'Y-m-d',
										itemCls : 'form_text'
									}, {
										xtype : 'datefield',
										name : 'endTime',
										editable : false,
										id : 'endTime',
										fieldLabel : '结束日期',
										format : 'Y-m-d',
										itemCls : 'form_text'
									}],
							buttons : [{
								text : '查找',
								type : 'submit',
								handler : function() {
								
									var startTime = Ext.getCmp('startTime').getValue();
									var endTime = Ext.getCmp('endTime').getValue();
									
									if(startTime > endTime)
									{
										Ext.Msg.show({
											title : '错误提示',
												msg : '开始时间必须小于结束时间！',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.INFO,
												width : 200
											});
										return;
									}

									ds.baseParams = manuscriptWorkForm
											.getForm().getValues();
									ds.load({
												params : {
													start : 0,
													limit : 20
												}
											});
									window_select_manuscriptwork.remove(Ext.getCmp('bb'));
									window_select_manuscriptwork.close();
								}
							},{
								text:'重置',
								type: 'reset',
								handler:function(){
									manuscriptWorkForm.form.reset();
								}
							},{
								text:'取消',
								handler:function(){
								window_select_manuscriptwork.remove(Ext.getCmp('bb'));
								window_select_manuscriptwork.close();	
							}
							}]

						});
				var window_select_manuscriptwork = new Ext.Window({
							title : '查找稿件工作',
							width : 600,
							iconCls:"manuscript_search",
							resizable : false,
							autoHeight : true,
							constrain :true,
							modal : true,
							closeAction : 'hide',
							closable : false,
							items : manuscriptWorkForm
						}).show();

			}
		});


var manuscriptList = new Ext.data.JsonStore({
			url : 'manuscript_list.action',
			root : 'manuScripts',
			fields : ['manuscriptId', 'title']
		});

manuscriptList.load();

 var list_allManuscriptWorks = new Ext.Button({
	
	text : '列出所有稿件工作',
	iconCls:'manuscriptWork_manager',
	width : 100,
	handler : function() {
	 	ds.baseParams = null;
	 	ds.load({
			params : {
				start : 0,
				limit : 20,
				requesterSecurityGrade : '5',
				manuscriptWorkType : '',
				manuscriptWorkStatus : '',
				startTime : '',
				endTime : '',
				order : 0
			}
		});
	}
	
});


var grid = new Ext.grid.GridPanel({
			title : '当前位置：稿件工作管理',
			loadMask : {
				msg : '数据加载中...'
			},
			ds : ds,
			store : ds,
			region : 'center',
			autoScroll : true,
			cm : cm_menuscriptWork,
//			autoExpandColumn : 1,
			tbar : [select_manuscriptWork,list_allManuscriptWorks],
			bbar : new Ext.PagingToolbar({
						pageSize : 20,
						store : ds,
						displayInfo : true,
						beforePageText : '第',
						afterPageText : '页-共{0}页',
						displayMsg : '显示{0} - {1} 条  共 {2} 条',
						emptyMsg : "没有记录"
					})
		});
ds.load({
			params : {
				start : 0,
				limit : 20
			}
		});


function changeRemark(respText){
    return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showRemark('" + respText.manuscript.manuscriptId + "')>备注详情</a></div>";
}

function changeWorkRemark(respText){
    return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showWorkRemark('" + respText.manuscript.manuscriptId + "','" + respText.manuscriptWork.manuscriptWorkId + "')>备注详情</a></div>";
}

window.showRemark = function(v){
    Ext.Ajax.request({
        url: 'manuscript_view.action',
        method: 'post',
        params: {
            manuscriptId: v
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscript.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
};

window.showWorkRemark = function(v1,v2){
    Ext.Ajax.request({
        url: 'manuscriptWork_view.action',
        method: 'post',
        params: {
            manuscriptId: v1,
            manuscriptWorkId : v2
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscriptWork.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
};
	

window.showManuscript = function(needParam) {
	Ext.Ajax.request({
		url : 'manuscript_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			var manuscript = respText.manuscript;
			var type = '';
			var language = '';
			var targetLanguage = '';
			var status = '';
			var urgence = '';
			var securityClassification = '';
			if (manuscript.type == 0) {
				type = '纸质稿件';
			} else {
				type = '电子稿件';
			}
			if (manuscript.language == 1) {
				language = '汉语';
			} else {
				language = '藏语';
			}
			if (manuscript.targetLanguage == 1) {
				targetLanguage = '汉语';
			} else {
				targetLanguage = '藏语';
			}
			if (manuscript.status == 0) {
				status = '草稿';
			} else if (manuscript.status == 1) {
				status = '原稿';
			} else if (manuscript.status == 2) {
				status = '翻译中';
			} else if (manuscript.status == 3) {
				status = '翻译完成';
			} else if (manuscript.status == 4) {
				status = '校审中';
			} else if (manuscript.status == 5) {
				status = '校审完成';
			} else if (manuscript.status == 6) {
				status = '校对中';
			} else if (manuscript.status == 7) {
				status = '校对完成';
			} else if (manuscript.status == 8) {
				status = '审核中';
			} else if (manuscript.status == 9) {
				status = '审核完成';
			} else {
				status = '已发排';
			};

			if (manuscript.urgence == 0) {
				urgence = '普通';
			} else if (manuscript.urgence == 5) {
				urgence = '紧急';
			} else if (manuscript.urgence == 10) {
				urgence = '特急';
			}

			if (manuscript.securityClassification == 1) {
				securityClassification = '普通';
			} else if (manuscript.securityClassification == 2) {
				securityClassification = '秘密';
			} else if (manuscript.securityClassification == 3) {
				securityClassification = '机密';
			} else if (manuscript.securityClassification == 5) {
				securityClassification = '绝密';
			}

			if (respText.success) {
				var manuscriptWork_show= new Ext.Window({
					title : '稿件详情',
					width : 600,
					iconCls:'manuscript_manager',
					resizable : false,
					autoHeight : true,
					modal : true,
					closeAction : 'hide',
					closable : false,
					items : [new Ext.FormPanel({
								border : false,
								frame : true,
								labelAlign : 'right',
								labelWidth : 100,
								defaults : {
									itemCls : 'form_text unedit',
									msgTarget : 'side'
								},
								defaultType : 'textfield',
								items : [{
											fieldLabel : '稿件标题',
											value : manuscript.title,
											readOnly : true,
											itemCls : 'form_long clear unedit',
											width : 426
										}, {
											autoHeight : true,
											xtype : 'textfield',
											fieldLabel : '稿件编号',
											readOnly : true,
											value : respText.manuscript.manuscriptCode,
											itemCls:'form_text unedit'
										}, {
											fieldLabel : '文档类型',
											value : type,
											readOnly : true
										}, {
											fieldLabel : '稿件分类',
											value : manuscript.manuscriptCategory.manuscriptCategoryName,
											readOnly : true
										},{
											fieldLabel : '来稿单位',
											value : manuscript.contributeCompany.contributeCompanyName,
											readOnly : true
										}, {
											xtype : 'textfield',
											fieldLabel : '来稿单位类型',
											readOnly : true,
											value : respText.manuscript.contributeCompany.type,
											itemCls:'form_text unedit'
										},{
											fieldLabel : '联系人',
											value : manuscript.contributeCompanyPerson.name,
											readOnly : true
										},{
											fieldLabel : '联系人手机',
											value : manuscript.contributeCompanyPerson.mobilePhone,
											readOnly : true
										},{
											fieldLabel : '联系人电话',
											value : manuscript.contributeCompanyPerson.telephone,
											readOnly : true
										},{
											fieldLabel : '联系人邮箱',
											value : manuscript.contributeCompanyPerson.email,
											readOnly : true
										},{
											fieldLabel : '原稿文种',
											value : language,
											readOnly : true
										}, {
											fieldLabel : '目标语言',
											value : targetLanguage,
											readOnly : true
										}, {
											fieldLabel : '稿件状态',
											value : status,
											readOnly : true
										}, {
											fieldLabel : '紧急程度',
											value : urgence,
											readOnly : true
										}, {
											fieldLabel : '稿件密级',
											value : securityClassification,
											readOnly : true
										}, {
											fieldLabel : '字数',
											value : manuscript.wordNum,
											readOnly : true
										}, {
											fieldLabel : '稿件创建人',
											value : manuscript.creatorName,
											readOnly : true
										}, {
											fieldLabel : '来稿时间',
											value : formatTime(manuscript.contributeTime,"",""),
											readOnly : true
										}, {
											fieldLabel : '计划完成时间',
											value : formatTime(manuscript.plannedConsummationTime,"",""),
											readOnly : true
										},{
											fieldLabel : '实际完成时间',
											value : formatTime(manuscript.actualConsummationTime,"",""),
											readOnly : true
										}, {
											fieldLabel : '最后修改人',
											value : manuscript.lastModifierName,
											readOnly : true
										}, {
											fieldLabel : '最后修改时间',
											value : formatTime(manuscript.lastModifiedTimestamp,"",""),
											readOnly : true
										}, {
											fieldLabel : '发排人',
											value : manuscript.releaserName,
											readOnly : true
										}, {
											fieldLabel : '发排时间',
											value : formatTime(manuscript.releaseTimeStamp,"",""),
											readOnly : true
										},{
											fieldLabel: '备注',
					                         xtype: 'panel',
					                         width: 425,
					                         itemCls: 'clear',
					                         html: changeRemark(respText)
										}],
										buttons:[{
											text:'关闭',
											handler:function(){
											manuscriptWork_show.close();
										}
										}]
							})]

				}).show();
			} else {
				Ext.Msg.show({
					title : '错误提示',
					msg : '查看稿件工作详情失败！',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
			}
		},
		failure : function() {
			Ext.Msg.show({
						title : '错误提示',
						msg : '查看稿件工作详情失败！',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	});
};

listWorker = function(value){
	var temp = "";
	for (var i = 0; i < value.length; i++) {
		temp = temp + value[i].manuscriptWorkerName + "; ";
	}
	return temp;
};
window.showManuscriptWork = function(needParam1,needParam2) {
	Ext.Ajax.request({
		url : 'manuscriptWork_view.action',
		methord : 'post',
		params : {
			manuscriptId : needParam1,
			manuscriptWorkId : needParam2
			
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			var manuscriptWork = respText.manuscriptWork;
			var manuscript = respText.manuscript;
			var type = '';
			var status = '';

			if (manuscriptWork.type == 1) {
				type = '翻译';
			} else if (manuscriptWork.type == 2) {
				type = '校审';
			} else if (manuscriptWork.type == 3) {
				type = '校对';
			} else {
				type = '审核';
			}

			if (manuscriptWork.status == 1) {
				status = '分发完成';
			} else if (manuscriptWork.status == 2) {
				status = '工作进行中';
			} else if (manuscriptWork.status == 3) {
				status = '工作完成';
			} else if (manuscriptWork.status == 4) {
				status = '工作部分完成';
			} else if (manuscriptWork.status == 10) {
				status = '工作被拒绝';
			} else {
				status = '工作被取消';
			}

			if (respText.success) {
			var	manuscriptWorkshow=new Ext.Window({
					title : '稿件工作详情',
					constrain :true,
					width : 600,
					constrain :true,
					resizable : false,
					autoHeight : true,
					modal : true,
					closeAction : 'hide',
					closable : false,
					items : [new Ext.FormPanel({
								border : false,
								frame : true,
								labelAlign : 'right',
								labelWidth : 110,
								defaults : {
									itemCls : 'form_text',
									msgTarget : 'side'
								},
								defaultType : 'textfield',
								items : [{
											fieldLabel : '工作类型',
											value : type,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作状态',
											value : status,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '字数',
											value : manuscriptWork.wordNum,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, /*{
											fieldLabel : '稿件分类',
											value : manuscript.manuscriptCategory.manuscriptCategoryName,
											readOnly : true,
											itemCls : 'form_text unedit'
										},*/ {
											fieldLabel : '分发人',
											value : manuscriptWork.assignerName,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作人数',
											value : manuscriptWork.workerNum,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '创建时间',
											value : formatTime(manuscriptWork.startTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作开始时间',
											value : formatTime(manuscriptWork.startTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '要求完成时间',
											value : formatTime(manuscriptWork.plannedFinishedTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '实际完成时间',
											value : formatTime(manuscriptWork.actualFinishedTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作确认人',
											value : manuscriptWork.confirmerName,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '确认时间',
											value : formatTime(manuscriptWork.confirmedTimestamp,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										},{
											fieldLabel : '工作统稿人',
											value : manuscriptWork.principalName,
											readOnly : true,
											itemCls : 'form_text unedit'
										},{
											fieldLabel : '工作人员',
											value : listWorker(manuscriptWork.manuscriptWorkers),
											anchor : '95%',
											readOnly : true,
											itemCls : 'form_long unedit'
										},{
											fieldLabel: '工作备注',
					                         xtype: 'panel',
					                         width: 425,
					                         itemCls: 'clear',
					                         html: changeWorkRemark(respText)
										}],
										buttons:[{
											text:'关闭',
											handler:function(){
											manuscriptWorkshow.close();
										}
										}]
							})]

				}).show();
			} else {
				Ext.Msg.show({
					title : '错误提示',
					msg : respText.msg,
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
			}
		},
		failure : function() {
			Ext.Msg.show({
						title : '错误提示',
						msg : '查看失败',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	});
};

addColor = function(param) {
	if (param == 256) {
		return 'text-green';
	} else if (param == 512) {
		return 'text-blue';
	} else if (param == 768) {
		return 'text-red';
	} else {
		return 'text-gray';
	}
};

isDisables = function(param) {
	if (param == 4096) {
		return true;
	} else {
		return false;
	}
};



function totime(value, metadata, record) {
	return new Date(value).format('Y-m-d');
}

function tourgence(value) {
	switch (value) {
		case 0 :
			return "普通";
			break;
		case 5 :
			return "紧急";
			break;
		case 10 :
			return "特急";
			break;
	}
}

function tosecurityClassification(value) {
	switch (value) {
		case 1 :
			return "普通";
			break;
		case 2 :
			return "秘密";
			break;
		case 3 :
			return "机密";
			break;
		case 5 :
			return "绝密";
			break;
	}
}


function tolanguage(value) {
	switch (value) {
		case 1 :
			return "汉语";
			break;
		case 2 :
			return "藏语";
			break;
	}
}

function totargetLanguage(value) {
	switch (value) {
		case 1 :
			return "汉语";
			break;
		case 2 :
			return "藏语";
			break;
	}
}

function totexttype(value) {
	switch (value) {
		case 0 :
			return "纸质稿件";
			break;
		case 0x0100 :
			return "电子稿件";
			break;
	}
}

function totype(value) {
	if(value=="DW"){
		return "党委";
	}else if(value=="RD"){
		return "人大";
	}else if(value=="ZF"){
		return "政府";
	}else if(value=="ZX"){
		return "政协";
	}else if(value=="QT"){
		return "其他";
	}else{
		return value;
	}
}

function formchange(respText) {
	urgence = tourgence(respText.manuscript.urgence);
	securityClassification = tosecurityClassification(respText.manuscript.securityClassification);
	language = tolanguage(respText.manuscript.language);
	targetLanguage = totargetLanguage(respText.manuscript.targetLanguage);
	contributeTime = totime(respText.manuscript.contributeTime, "", "");
	plannedConsummationTime = totime(
	 respText.manuscript.plannedConsummationTime, "", "");
	texttype = totexttype(respText.manuscript.type);
	type = totype(respText.contributeCompany.type);
}


function toSecurityGrade(value) {
	switch (value) {
		case 1 :
			return "普通";
			break;
		case 2 :
			return "秘密";
			break;
		case 3 :
			return "机密";
			break;
		case 5 :
			return "绝密";
			break;
	}
}

var manuscriptWork_tabPanel = new Ext.TabPanel({
	id : 'centerTabPanel',
	region : 'center',
	deferredRender : true,
	enableTabScroll : true,
	height : 650,
	autoScroll : true,
	activeTab : 0, // first tab initially active
	defaults : {
		closable : false
	},
	items : [grid]
});

//周振山修改Start
var toptip = "";
workShowadd = function(metadata,userId){
	Ext.Ajax.request({
		url : 'worksByPerson_list.action',
		method : 'post',
		async : false, 
		params : {
			userId : userId
		},
		success : function(resp, opts) {
			toptip = "";
			var respText = Ext.util.JSON.decode(resp.responseText);
			if(respText.success){
				manuscriptWorksByPerson = respText.manuscriptWorksByPerson;
				if(manuscriptWorksByPerson.length != 0){
					for (var i = 0; i < manuscriptWorksByPerson.length; i++) {
						if(manuscriptWorksByPerson[i].manuscript.title.length >10){
							toptip = toptip + escapeHTML(manuscriptWorksByPerson[i].manuscript.title.substring(0,10)) + "..." + "</br>";
						}else{
							toptip = toptip + escapeHTML(manuscriptWorksByPerson[i].manuscript.title) + "</br>";
						}
					}
				}
			}
		}
	});
	metadata.attr = ' ext:qtip="' + toptip + '"';
};

//end

window.addScriptWorker = function(needParam1,needParam2) {
	if(Ext.get('win_add_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	if(Ext.get('win_delete_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	
	Ext.Ajax.request({
		url : 'manuscriptWork_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam1,
			manuscriptWorkId : needParam2
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			if (respText.success) {
				formchange(respText);
				var ds_add_disrtibuter = new Ext.data.Store({
							proxy : new Ext.data.MemoryProxy(respText),
							reader : new Ext.data.JsonReader({
								root : 'usersForDistribute'
							}, [{name : 'userId',mapping : 'userId',type : 'long'},
								{name : 'userName',mapping : 'userName',type : 'string'},
								{name : 'status',mapping : 'status',type : 'long'},
								{name : 'ability',mapping : 'ability',type : 'long'},
								{name : 'status',mapping : 'status',type : 'long'},
								{name : 'securityGrade',mapping : 'securityGrade',type : 'long'}]
						)
				});
				var sm_add_user=new Ext.grid.CheckboxSelectionModel();
				var cm_add_worker = new Ext.grid.ColumnModel([
					new Ext.grid.RowNumberer(),
					{header:'稿件工作人员',dataIndex:'userName',renderer:function(value, metadata, record)
						{
						//添加
						   workShowadd(metadata,record.data.userId);
			    	    	return "<input type='checkbox' name='manuscriptWorkersId' value='"+record.data.userId+"' )>  <font color='"+addColor(record.data.status)+"'>"+record.data.userName+"</font></input>";
						}
					},
					
					{header:'能力级别',dataIndex:'ability',width:150,sortable:true},
					{header:'安全等级',dataIndex:'securityGrade',width:150,sortable:true,renderer: function change(value, metadata, record){
					        return tosecurityClassification(value, metadata, record);
					    }
					}
				]);
				
				var grid_disrtibuter = new Ext.grid.GridPanel({
					loadMask : {
						msg : '数据加载中...'
					},
					ds : ds_add_disrtibuter,
					store : ds_add_disrtibuter,
					region : 'form_distributer',
					autoScroll : true,
					cm : cm_add_worker,
					autoExpandColumn : 1,
					autoHeight : true
					//height : 380
				});
				ds_add_disrtibuter.load({
						params : {
							start : 0,
							limit : 20
						}
				});
				var form_add_worker = new Ext.form.FormPanel({
					title : '增加稿件工作人员',
					resizable : false,
					id : 'form_distributer',
					autoHeight : true,
					//height:390,
					plain : true,
					modal : true,
					labelAlign : 'right',
					frame : true,
					items : [grid_disrtibuter],
					buttons : [{
						text : '增加',
						type : 'submit',
						handler : function() {
							form_add_worker.form.doAction('submit', {
								url : 'manuscriptWork_add.action',
								method : 'post',
								params : {
									manuscriptWorkId : needParam2
								},
								success : function(form, action) {
									if (action.result.success) {
										Ext.Msg.show({
													title : '操作提示',
													msg : '增加成功！',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.INFO,
													width : 200
												});
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
										manuscriptWork_tabPanel.setActiveTab(0);
										ds.load({params:{start:0,limit:20}});
										ds_add_disrtibuter.reload();
									} else {
										Ext.Msg.show({
													title : '错误提示',
													msg : '增加失败！',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
									}
								},
								failure : function(from, action) {
									Ext.Msg.show({
												title : '错误提示',
												msg : '增加失败！',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.ERROR,
												width : 200
											});
								}
							});
						}
					},{
					     		text : '关闭',
					     		handler : function() {
									manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
									manuscriptWork_tabPanel.setActiveTab(0);
								}
					     	}]
				});
				var win_add_work ={
						title : '增加稿件工作人员',
						autoWidth : true,
						autoHeight:true,
						closable : true,
						id : 'win_add_work',
						autoScroll : true,
						modal : true,
						items : [form_add_worker]
					};
				manuscriptWork_tabPanel.add(win_add_work);
				manuscriptWork_tabPanel.setActiveTab(1);
		} else {
			Ext.Msg.show({
						title : '错误提示',
						msg : '获取稿件工作人员失败！',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	},
	failure : function() {
		Ext.Msg.show({
					title : '错误提示',
					msg : '加载失败！',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
	}
});
};

//减少人员
window.deleteScriptWorker = function(needParam1,needParam2) {
	if(Ext.get('win_add_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	if(Ext.get('win_delete_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}

	Ext.Ajax.request({
		url : 'manuscriptWork_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam1,
			manuscriptWorkId : needParam2
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			
			var manuscriptWorkers = respText.manuscriptWorkers;
			
			if(manuscriptWorkers.length == 0)
			{
				Ext.Msg.show({
                    title: '信息',
                    msg: '无可供减少的工作人员！',
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO,
                    width: 200
                });
				return;
			}
			
			if (respText.success) {
				formchange(respText);
				var ds_delete_disrtibuter = new Ext.data.Store({
					proxy : new Ext.data.MemoryProxy(respText),
					reader : new Ext.data.JsonReader({
								root : 'manuscriptWorkers'
							}, [{name : 'manuscriptWorkerId',mapping : 'manuscriptWorkerId',type : 'long'},
								{name : 'manuscriptWorkerName',mapping : 'manuscriptWorkerName',type : 'string'},
								{name : 'status',mapping : 'status',type : 'short'},
								{name : 'description',mapping : 'description',type : 'string'}]
						)
				});
				
				var cm_delete_worker = new Ext.grid.ColumnModel([
					new Ext.grid.RowNumberer(),
						{header:'稿件工作人员',dataIndex:'userName',renderer:function(value, metadata, record)
							{
								workShowadd(metadata,record.data.manuscriptWorkerId);
								return "<input type='checkbox' name='userIds' value='"+record.data.manuscriptWorkerId+"' )>  <font color='"+addColor(record.data.status)+"'>"+record.data.manuscriptWorkerName+"</font></input>";
							}
						},
						{header:'稿件工作人员状态',dataIndex:'status',width:150,sortable:true,renderer : function(value, metadata, record)
							{
								if(value == 0)
								{
									return "分发完成";
								}else if(value == 1)
								{
									return "已分配";
								}else if(value == 2)
								{
									return "接受";
								}else if(value == 3)
								{
									return "拒绝";
								}else if(value == 4)
								{
									return "提交完成";
								}else if(value == 5)
								{
									return "被确认完成";
								}
							}
						},
						{header:'任务描述',dataIndex:'description',width:150,sortable:true}
					]);

					var grid_disrtibuter = new Ext.grid.GridPanel({
						loadMask : {
							msg : '数据加载中...'
						},
						ds : ds_delete_disrtibuter,
						store : ds_delete_disrtibuter,
						region : 'form_distributer',
						autoScroll : true,
						cm : cm_delete_worker,
						autoExpandColumn : 1,
						autoHeight : true
						//height : 380
					});
					ds_delete_disrtibuter.load({
							params : {
								start : 0,
								limit : 20
							}
					});                                    		
				var form_delete_worker = new Ext.form.FormPanel({
					title : '减少稿件工作人员',
					resizable : false,
					id : 'form_distributer',
					autoHeight : true,
					//height:390,
					plain : true,
					modal : true,
					labelAlign : 'right',
					frame : true,
					items : [grid_disrtibuter],
					buttons : [{
						text : '减少',
						type : 'submit',
						handler : function() {
							form_delete_worker.form.doAction('submit', {
								url : 'manuscriptWork_delete.action',
								method : 'post',
								params : {
									manuscriptWorkId : needParam2
								},
								success : function(form, action) {
									if (action.result.success) {
										Ext.Msg.show({
													title : '操作提示',
													msg : '减少成功!',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.INFO,
													width : 200
												});
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
										manuscriptWork_tabPanel.setActiveTab(0);
										ds.load({params:{start:0,limit:20}});
										ds_delete_disrtibuter.reload();
									} else {
										Ext.Msg.show({
													title : '错误提示',
													msg : '减少失败',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
									}
								},
								failure : function(from, action) {
									Ext.Msg.show({
												title : '错误提示',
												msg : '减少失败',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.ERROR,
												width : 200
											});
								}
							});
						}
					},{
					     		text : '关闭',
					     		handler : function() {
									manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
									manuscriptWork_tabPanel.setActiveTab(0);
								}
					     	}]
				});
				var win_delete_work ={
						title : '减少稿件工作人员',
						autoWidth : true,
						autoHeight:true,
						closable : true,
						autoScroll : true,
						id : 'win_delete_work',
						modal : true,
						items : [form_delete_worker]
					};
			manuscriptWork_tabPanel.add(win_delete_work);
			manuscriptWork_tabPanel.setActiveTab(1);
		} else {
			Ext.Msg.show({
						title : '错误提示',
						msg : '获取稿件工作人员失败！',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	},
	failure : function() {
		Ext.Msg.show({
					title : '错误提示',
					msg : '加载失败！',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
	}
});
};

//取消工作
window.cancelManuscriptWork = function(needParam) {
	Ext.Msg.confirm('取消确认', '你确定取消?', function(btn) {
		if (btn == 'yes') {
			Ext.Ajax.request({
				url : "manuscriptWork_cancel.action",
				method : 'post',
				params : {
					manuscriptWorkId: needParam
				},
				success : function(resp, opts) {
					
					var respText = Ext.util.JSON.decode(resp.responseText);
					if (respText.success) {
						if(respText.msg == 'wrong')
						{
							Ext.Msg.show({
								title : '错误提示',
								msg : '取消失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
						}
						else if(respText.msg == 'ok')
						{  
							   Ext.Msg.show({ 
								title : '正确提示',
								msg : '取消稿件工作成功!',
								buttons : Ext.Msg.OK,
								
								width : 200
							      });
							   ds.load({
			     	  	    				 params:{
			     	  	    				 	start:0,
			     	  	    				 	limit:20
			     	  	    				 }
			     	  	    			});
						}
					} else {
						Ext.Msg.show({
							title : '错误提示',
							msg : '取消失败!',
							buttons : Ext.Msg.OK,
							icon : Ext.Msg.ERROR,
							width : 200
						});
					
						 ds.load({
			     	  	    				 params:{
			     	  	    				 	start:0,
			     	  	    				 	limit:20
			     	  	    				 }
			     	  	    			});
					}
				},
				failure : function() {
					Ext.Msg.show({
								title : '错误提示',
								msg : '修改失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
				}
			});
		}
	});
};



//时间格式转换
function formatTime(value, metadata, record){
	if(null==value){
		return null;
	}else{
		return new Date(value).format('Y-m-d H:i');
	}
}

var p_menuScript = {
	id : 'manuscriptWork-search',
	border : false,
	layout : 'border',
	items : [manuscriptWork_tabPanel]
};
Ext.getCmp('content-panel').add(p_menuScript);
Ext.getCmp('content-panel').layout.setActiveItem('manuscriptWork-search');
